
<template>
  <!--  导航栏-->
  <el-row>
    <el-col :span="24">
      <el-breadcrumb separator=">">
        <el-breadcrumb-item>首页</el-breadcrumb-item>
        <el-breadcrumb-item>质量管理</el-breadcrumb-item>
        <el-breadcrumb-item>检测项设置</el-breadcrumb-item>
      </el-breadcrumb>
    </el-col>
  </el-row>
<!--  搜索栏-->
  <el-row>
    <el-col :span="24" style="margin-top: 15px">
      <el-form inline label-width="auto" :model="testingTemplateQuery">
        <el-form-item label="检测模版编号">
          <el-input clearable placeholder="请输入内容" v-model="testingTemplateQuery.testingTemplateId"></el-input>
        </el-form-item>
        <el-form-item label="检测项名称">
          <el-input clearable placeholder="请输入内容" v-model="testingTemplateQuery.testingTemplateName"></el-input>
        </el-form-item>
        <el-form-item label="检测种类">
          <el-checkbox-group v-model="testingTemplateQuery.testingTemplateType">
            <el-checkbox :value="1">来料检验</el-checkbox>
            <el-checkbox :value="2">过程检验</el-checkbox>
            <el-checkbox :value="3">首检</el-checkbox>
            <el-checkbox :value="4">末检</el-checkbox>
            <el-checkbox :value="5">巡检</el-checkbox>
            <el-checkbox :value="6">自检</el-checkbox>
            <el-checkbox :value="7">成品检验</el-checkbox>
            <el-checkbox :value="8">发货检验</el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="loadTestingTemplate">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
<!--  工具栏-->
  <el-row style="margin-top: 15px">
    <el-col :span="24">
      <el-button type="primary" @click="addTestingTemplate">新增</el-button>
      <el-button type="primary">修改</el-button>
      <el-button type="primary" @click="deleteTestingTemplates">删除</el-button>
    </el-col>
  </el-row>
<!--  内容栏-->
  <el-row style="margin-top: 15px">
    <el-col :span="24">
      <el-table stripe border style="width: 100%" :data="testingTemplates" @selection-change="selectTestingTempalate">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="testingTemplateId" label="检测项编号" width="150" >
          <template #default="scope">
            <el-link type="primary" @click="detailTestingTemplate(scope.row.testingTemplateId)">{{scope.row.testingTemplateId}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="testingTemplateName" label="检测项名称" width="150"></el-table-column>
        <el-table-column prop="testingTemplateType" label="检测种类" width="150">
          <template #default="scope">
            <el-tag type="success" v-if="scope.row.testingTemplateType == 1">来料检验</el-tag>
            <el-tag type="warning" v-else-if="scope.row.testingTemplateType == 2">过程检验</el-tag>
            <el-tag type="danger" v-else-if="scope.row.testingTemplateType == 3">首检</el-tag>
            <el-tag type="info" v-else-if="scope.row.testingTemplateType == 4">末检</el-tag>
            <el-tag type="primary" v-else-if="scope.row.testingTemplateType == 5">巡检</el-tag>
            <el-tag type="info" v-else-if="scope.row.testingTemplateType == 6">自检</el-tag>
            <el-tag type="info" v-else-if="scope.row.testingTemplateType == 7">成品检验</el-tag>
            <el-tag type="info" v-else-if="scope.row.testingTemplateType == 8">发货检验</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="testingTemplateEnable" label="是否启用" width="150">
          <template #default="scope">
            <el-tag type="success" v-if="scope.row.testingTemplateEnable == 1">启用</el-tag>
            <el-tag type="danger" v-else-if="scope.row.testingTemplateEnable == 2">禁用</el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template #default="scope">
            <el-button type="text" @click="editTestingTemplate(scope.row.testingTemplateId)">修改</el-button>
            <el-button type="text" @click="deleteTestingTemplateById(scope.row.testingTemplateId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
  </el-row>
<!--  分页栏-->
  <el-row style="margin-top: 15px">
    <el-row style="margin-top: 15px">
      <el-col :span="24">
        <el-pagination @change="changePage" background layout="prev, pager, next" :total="total"/>
      </el-col>
    </el-row>
  </el-row>
<!--  新增弹窗-->
  <el-dialog title="新增检测模板" v-model="addDialogVisible" width="80%">
    <el-form label-width="130px">
      <el-form-item label="检测项编号">
        <el-input placeholder="请输入检测项编号" v-model="newTestingTemplate.testingTemplateId"></el-input>
      </el-form-item>
      <el-form-item label="检测项名称">
        <el-input placeholder="请输入检测项名称" v-model="newTestingTemplate.testingTemplateName"></el-input>
      </el-form-item>
      <el-form-item label="检测项类型">
        <el-checkbox-group v-model="newTestingTemplate.testingProjectList">
          <el-checkbox :value="1">来料检验</el-checkbox>
          <el-checkbox :value="2">过程检验</el-checkbox>
          <el-checkbox :value="3">首检</el-checkbox>
          <el-checkbox :value="4">末检</el-checkbox>
          <el-checkbox :value="5">巡检</el-checkbox>
          <el-checkbox :value="6">自检</el-checkbox>
          <el-checkbox :value="7">成品检验</el-checkbox>
          <el-checkbox :value="8">发货检验</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
      <el-form-item label="是否启用">
        <el-radio-group v-model="newTestingTemplate.testingTemplateEnable">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="备注">
        <el-input placeholder="请输入备注" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitAddTetstingProject" >确定</el-button>
        <el-button @click="cancelAddTestingProject">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
<!--  编辑弹窗-->
  <el-dialog title="编辑检测模版" v-model="dialogVisibleEdit" width="50%" align-center>
    <el-form label-width="130px">
      <el-form-item label="检测模版名称">
        <el-input placeholder="请输入检测模版名称" v-model="selectByIdTestingTemplate.testingTemplateName"></el-input>
      </el-form-item>
      <el-form-item label="检测项类型">
        <el-radio-group v-model="selectByIdTestingTemplate.testingTemplateType">
          <el-radio-button :label="1">来料检验</el-radio-button>
          <el-radio-button :label="2">过程检验</el-radio-button>
          <el-radio-button :label="3">首检</el-radio-button>
          <el-radio-button :label="4">末检</el-radio-button>
          <el-radio-button :label="5">巡检</el-radio-button>
          <el-radio-button :label="6">自检</el-radio-button>
          <el-radio-button :label="7">成品检验</el-radio-button>
          <el-radio-button :label="8">发货检验</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否启用">
        <el-radio-group v-model="selectByIdTestingTemplate.testingTemplateEnable">
          <el-radio :label="1">是</el-radio>
          <el-radio :label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitEditTestingTemplate">确定</el-button>
        <el-button @click="cancelEditTestingTemplate">取消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
<!--  详情弹窗-->
  <el-dialog title="检测模版详情" v-model="dialogVisibleDetail" width="80%" align-center>
    <el-form label-width="130px" :model="selectByIdTestingTemplate">
      <el-form-item label="检测模版编号">
        <el-input v-model="selectByIdTestingTemplate.testingTemplateId" disabled></el-input>
      </el-form-item>
      <el-form-item label="检测模版名称">
        <el-input v-model="selectByIdTestingTemplate.testingTemplateName" disabled></el-input>
      </el-form-item>
      <el-form-item label="检测模版类型">
        <el-radio-group v-model="selectByIdTestingTemplate.testingTemplateType" disabled>
          <el-radio-button :label="1">来料检验</el-radio-button>
          <el-radio-button :label="2">过程检验</el-radio-button>
          <el-radio-button :label="3">首检</el-radio-button>
          <el-radio-button :label="4">末检</el-radio-button>
          <el-radio-button :label="5">巡检</el-radio-button>
          <el-radio-button :label="6">自检</el-radio-button>
          <el-radio-button :label="7">成品检验</el-radio-button>
          <el-radio-button :label="8">发货检验</el-radio-button>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="是否启用">
        <el-radio-group v-model="selectByIdTestingTemplate.testingTemplateEnable" disabled>
          <el-radio :label="1">是</el-radio>
          <el-radio :label="2">否</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
        <el-tabs type="border-card">
          <el-tab-pane label="检测项">
            <!--  工具栏-->
            <el-row style="margin-top: 15px">
              <el-col :span="24">
                <el-button type="primary" @click="addTestingProject">新增</el-button>
                <el-button type="primary" @click="deleteTestingTemplateProjects">删除</el-button>
              </el-col>
            </el-row>
<!--    内容栏-->
            <el-table border stripe :data="testingTemplateProjects" @selection-change="selectTestingTemplateProject">
              <el-table-column type="selection" width="55" align="center"></el-table-column>
              <el-table-column prop="testingProjectName" label="检测项名称" width="120"></el-table-column>
              <el-table-column prop="testingProjectType" label="检测项类型" width="120">
                <template #default="scope">
                  <el-tag type="success" v-if="scope.row.testingProjectType == 1">尺寸</el-tag>
                  <el-tag type="warning" v-else-if="scope.row.testingProjectType == 2">外观</el-tag>
                  <el-tag type="danger" v-else-if="scope.row.testingProjectType == 3">重量</el-tag>
                  <el-tag type="info" v-else-if="scope.row.testingProjectType == 4">性能</el-tag>
                  <el-tag type="primary" v-else-if="scope.row.testingProjectType == 5">成分</el-tag>
                </template>
              </el-table-column>
              <el-table-column prop="testingProjectTool" label="检测工具" width="120"></el-table-column>
              <el-table-column prop="testingProjectStandard" label="检测标准" width="120"></el-table-column>
              <el-table-column prop="testingProjectMethod" label="检测方法" width="120"></el-table-column>
              <el-table-column prop="testingProjectUnit" label="检测单位" width="120"></el-table-column>
              <el-table-column prop="testingProjectErrorMax" label="误差上限" width="120"></el-table-column>
              <el-table-column prop="testingProjectErrorMin" label="误差下限" width="120"></el-table-column>
              <el-table-column fixed="right" label="操作" width="100">
                <template #default="scope">
                  <el-button type="text" @click="editSubmitTestingProject(scope.row.testingProjectId)">修改</el-button>
                  <el-button type="text" @click="deleteTestingTemplateProject(scope.row.testingProjectId)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!--  分页栏-->
            <el-row style="margin-top: 15px">
              <el-row style="margin-top: 15px">
                <el-col :span="24">
                  <el-pagination @change="changePageProject" background layout="prev, pager, next" :total="totalProject"/>
                </el-col>
              </el-row>
            </el-row>
          </el-tab-pane>
          <el-tab-pane label="物料产品">
<!--            工具栏-->
            <el-row style="margin-top: 15px">
              <el-col :span="24">
                <el-button type="primary" @click="addMaterialProducts">新增</el-button>
                <el-button type="primary" @click="deleteMaterialProductsById">删除</el-button>
              </el-col>
            </el-row>
<!--            内容栏-->
            <el-table border stripe :data="materialProductses" @selection-change="selectMaterialProductDeleteId">
              <el-table-column  type="selection" width="55" align="center"></el-table-column>
              <el-table-column prop="materialProductId" label="物料产品编号" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductName" label="物料产品名称" width="120" align="center"></el-table-column>
              <el-table-column prop="specificationModel" label="规格型号" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductTestingMin" label="最低检测数" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductUnit" label="单位" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductsUnqualifiedMax" label="最大不合格数" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductsFatalFlawMax" label="最大致命缺陷率" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductsSevereFlawMax" label="最大严重缺陷率" width="120" align="center"></el-table-column>
              <el-table-column prop="materialProductsSlightFlawMax" label="最大轻微缺陷率" width="120" align="center"></el-table-column>
              <el-table-column fixed="right" label="操作" width="100" align="center">
                <template #default="scope">
                  <el-button type="text" @click="editMaterialProducts(scope.row.materialProductId)">修改</el-button>
                  <el-button type="text" @click="deleteMaterialProducts(scope.row.materialProductId)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
<!--            分页栏-->
            <el-row style="margin-top: 15px">
              <el-row style="margin-top: 15px">
                <el-col :span="24">
                  <el-pagination @change="changeMaterialProducts" background layout="prev, pager, next" :total="totalMaterial"/>
                </el-col>
              </el-row>
            </el-row>
          </el-tab-pane>
        </el-tabs>
<!--    检测项的新增弹窗-->
    <el-dialog title="新增检测项" v-model="dialogVisibleAddProject" width="50%" align-center>
      <el-form label-width="130px" :model="newTestingProject">
        <el-form-item label="检测项名称">
          <el-input v-model="newTestingProject.testingProjectName"></el-input>
        </el-form-item>
        <el-form-item label="检测项类型">
          <el-radio-group v-model="newTestingProject.testingProjectType">
            <el-radio :label="1">尺寸</el-radio>
            <el-radio :label="2">外观</el-radio>
            <el-radio :label="3">重量</el-radio>
            <el-radio :label="4">性能</el-radio>
            <el-radio :label="5">成分</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="检测工具">
          <el-input v-model="newTestingProject.testingProjectTool"></el-input>
        </el-form-item>
        <el-form-item label="检测标准">
          <el-input v-model="newTestingProject.testingProjectStandard"></el-input>
        </el-form-item>
        <el-form-item label="检测方法">
          <el-input v-model="newTestingProject.testingProjectMethod"></el-input>
        </el-form-item>
        <el-form-item label="检测单位">
          <el-input v-model="newTestingProject.testingProjectUnit"></el-input>
        </el-form-item>
        <el-form-item label="误差上限">
          <el-input v-model="newTestingProject.testingProjectErrorMax"></el-input>
        </el-form-item>
        <el-form-item label="误差下限">
          <el-input v-model="newTestingProject.testingProjectErrorMin"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="editTestingProject" >确定</el-button>
          <el-button @click="cancelAddTestingProject">取消</el-button>
        </el-form-item>
      </el-form>
  </el-dialog>
<!--    检测项的编辑弹窗-->
    <el-dialog title="编辑检测项" v-model="dialogVisibleEditProject" width="50%" align-center>
      <el-form label-width="130px">
        <el-form-item label="检测项编号">
          <el-input placeholder="请输入检测项编号" v-model="selectByIdTestingProjectTemplate.testingProjectId"></el-input>
        </el-form-item>
        <el-form-item label="检测项名称">
          <el-input placeholder="请输入检测项名称" v-model="selectByIdTestingProjectTemplate.testingProjectName"></el-input>
        </el-form-item>
        <el-form-item label="检测项类型">
          <el-select placeholder="请选择" style="width: 120px" v-model="selectByIdTestingProjectTemplate.testingProjectType">
            <el-option label="尺寸" :value="1"></el-option>
            <el-option label="外观" :value="2"></el-option>
            <el-option label="重量" :value="3"></el-option>
            <el-option label="性能" :value="4"></el-option>
            <el-option label="成分" :value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="检测工具">
          <el-input placeholder="请输入检测工具" v-model="selectByIdTestingProjectTemplate.testingProjectTool"></el-input>
        </el-form-item>
        <el-form-item label="检测标准">
          <el-input placeholder="请输入检测标准" v-model="selectByIdTestingProjectTemplate.testingProjectStandard"></el-input>
        </el-form-item>
        <el-form-item label="检测方法">
          <el-input placeholder="请输入检测方法" v-model="selectByIdTestingProjectTemplate.testingProjectMethod"></el-input>
        </el-form-item>
        <el-form-item label="检测单位">
          <el-input placeholder="请输入检测单位" v-model="selectByIdTestingProjectTemplate.testingProjectUnit"></el-input>
        </el-form-item>
        <el-form-item label="误差上限">
          <el-input placeholder="请输入误差上限" v-model="selectByIdTestingProjectTemplate.testingProjectErrorMax"></el-input>
        </el-form-item>
        <el-form-item label="误差下限">
          <el-input placeholder="请输入误差下限" v-model="selectByIdTestingProjectTemplate.testingProjectErrorMin"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitEditTestingProject">确定</el-button>
          <el-button @click="cancelEditTestingProject">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
<!--    物料产品的新增弹窗-->
    <el-dialog title="新增物料产品" v-model="dialogVisibleAddMaterial" width="50%" align-center>
      <el-form label-width="130px" :model="newMaterialProducts">
        <el-form-item label="物料产品编号">
          <el-input v-model="newMaterialProducts.materialProductId"></el-input>
        </el-form-item>
        <el-form-item label="物料产品名称">
          <el-input v-model="newMaterialProducts.materialProductName"></el-input>
        </el-form-item>
        <el-form-item label="规格型号">
          <el-input v-model="newMaterialProducts.specificationModel"></el-input>
        </el-form-item>
        <el-form-item label="最低检测数">
          <el-input v-model="newMaterialProducts.materialProductTestingMin"></el-input>
        </el-form-item>
        <el-form-item label="单位">
          <el-input v-model="newMaterialProducts.materialProductUnit"></el-input>
        </el-form-item>
        <el-form-item label="最大不合格数">
          <el-input v-model="newMaterialProducts.materialProductsUnqualifiedMax"></el-input>
        </el-form-item>
        <el-form-item label="最大致命缺陷率">
          <el-input v-model="newMaterialProducts.materialProductsFatalFlawMax"></el-input>
        </el-form-item>
        <el-form-item label="最大严重缺陷率">
          <el-input v-model="newMaterialProducts.materialProductsSevereFlawMax"></el-input>
        </el-form-item>
        <el-form-item label="最大轻微缺陷率">
          <el-input v-model="newMaterialProducts.materialProductsSlightFlawMax"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="addNewMaterialProducts" >确定</el-button>
          <el-button @click="cancelAddMaterialProducts">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
<!--    物料产品的编辑弹窗-->
    <el-dialog title="编辑物料产品" v-model="dialogVisibleEditMaterial" width="50%" align-center>
      <el-form label-width="130px">
        <el-form-item label="物料产品编号">
          <el-input placeholder="请输入物料产品编号" v-model="selectByIdMaterialProduct.materialProductId"></el-input>
        </el-form-item>
        <el-form-item label="物料产品名称">
          <el-input placeholder="请输入物料产品名称" v-model="selectByIdMaterialProduct.materialProductName"></el-input>
        </el-form-item>
        <el-form-item label="规格型号">
          <el-input placeholder="请输入规格型号" v-model="selectByIdMaterialProduct.specificationModel"></el-input>
        </el-form-item>
        <el-form-item label="最低检测数">
          <el-input placeholder="请输入最低检测数" v-model="selectByIdMaterialProduct.materialProductTestingMin"></el-input>
        </el-form-item>
        <el-form-item label="单位">
          <el-input placeholder="请输入单位" v-model="selectByIdMaterialProduct.materialProductUnit"></el-input>
        </el-form-item>
        <el-form-item label="最大不合格数">
          <el-input placeholder="请输入最大不合格数" v-model="selectByIdMaterialProduct.materialProductsUnqualifiedMax"></el-input>
        </el-form-item>
        <el-form-item label="最大致命缺陷率">
          <el-input placeholder="请输入最大致命缺陷率" v-model="selectByIdMaterialProduct.materialProductsFatalFlawMax"></el-input>
        </el-form-item>
        <el-form-item label="最大严重缺陷率">
          <el-input placeholder="请输入最大严重缺陷率" v-model="selectByIdMaterialProduct.materialProductsSevereFlawMax"></el-input>
        </el-form-item>
        <el-form-item label="最大轻微缺陷率">
          <el-input placeholder="请输入最大轻微缺陷率" v-model="selectByIdMaterialProduct.materialProductsSlightFlawMax"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitMaterialProducts" >确定</el-button>
          <el-button  @click="cancelEditMaterialProducts">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-button type="primary" @click="dialogVisibleDetail = false">确定</el-button>
  </el-dialog>
</template>
<script setup>
import {ref,onMounted} from 'vue';
import {useRouter,useRoute} from "vue-router";
import {ElMessage} from "element-plus";
import testingTemplate from "@/api/defece/testingTemplate.js";
import testingTemplateRequest from "@/api/defece/testingTemplate.js";
import testingProjectRequest from "@/api/defece/testingProject.js";
import materialProductsRequest from "@/api/defece/materialProducts.js";
// 封装查询对象
let testingTemplateQuery = ref({});
let testingTemplates = ref([]);
let curPage = ref(1);
let total = ref(0);
// 封装新增检测模板的信息
let newTestingTemplate = ref({});
// 新增弹窗的控制器
let addDialogVisible = ref(false);
// 编辑弹窗的控制器
let dialogVisibleEdit = ref(false);
// 根据id查询到的检测模板数据信息
let selectByIdTestingTemplate = ref({});
// 存放被选中的检测模板id
let selectTestingTemplateId = ref([]);
// 检测模版详情弹窗的控制器
let dialogVisibleDetail = ref(false);
// 封装查询到的检测项数据信息
let testingTemplateProjects = ref([]);
let totalProject = ref(0);
let curPageProject = ref(1);
// 检测项新增弹窗的控制器
let dialogVisibleAddProject = ref(false);
// 存放检测项的新增数据
let newTestingProject = ref({});
// 检测项编辑弹窗的控制事件
let dialogVisibleEditProject = ref(false);
// 根据id查询到的检测项信息
let selectByIdTestingProjectTemplate = ref({});
// 存放被选中的缺陷id
let testingTemplateProjectId= ref([])
// 封装物料产品查询信息
let materialProductses = ref([]);
let curPageMaterial = ref(1);
let totalMaterial = ref(0);
// 封装新增的物料产品信息
let newMaterialProducts = ref({});
// 物料产品新增弹窗的控制器
let dialogVisibleAddMaterial = ref(false);
// 物料产品编辑弹窗的控制器
let dialogVisibleEditMaterial = ref(false);
// 封装根据id查询到的物料产品信息
let selectByIdMaterialProduct = ref({});
// 封装被选中的物料产品id
let selectMaterialProductId = ref([]);
// 通过id对物料产品进行批量删除
function deleteMaterialProductsById(){
  for (let i = 0; i < selectMaterialProductId.value.length; i++){
    deleteMaterialProducts(selectMaterialProductId.value[i]);
  }
}
// 获取被选择的物料产品id
function selectMaterialProductDeleteId(queryTable){
  let listMaterialProduct = new Array();
  queryTable.forEach(item=>{
    listMaterialProduct.push(item.materialProductId);
    selectMaterialProductId.value = listMaterialProduct;
    console.log(selectMaterialProductId.value)
  })
}
// 删除物料产品
function deleteMaterialProducts(materialProductId){
  materialProductsRequest.loadDeleteMaterialProductById(materialProductId,res=>{
    if (res.code==200){
      ElMessage({
        message: "删除成功",
        type: "success"
      })
    }
    detailTestingTemplate(selectByIdTestingTemplate.value.testingTemplateId);
  })
}
// 物料产品编辑弹窗确认按钮的点击事件
function submitMaterialProducts(){
  materialProductsRequest.loadUpdateMaterialProduct(selectByIdMaterialProduct.value,res=>{
    if (res.code==200){
      ElMessage({
        message: "修改成功",
        type: "success"
      })
    }
    dialogVisibleEditMaterial.value = false;
    detailTestingTemplate(selectByIdTestingTemplate.value.testingTemplateId);
  })
}
// 物料产品编辑弹窗取消按钮的点击事件
function cancelEditMaterialProducts(){
  dialogVisibleEditMaterial.value = false;
  selectByIdMaterialProduct.value = {};
}
// 物料产品编辑按钮的点击事件
function editMaterialProducts(materialProductId){
  materialProductsRequest.loadSelectMaterialProductById(materialProductId,res=>{
    selectByIdMaterialProduct.value = res.data;
    dialogVisibleEditMaterial.value = true;
  })
}
// 新增物料产品按钮的点击事件
function addMaterialProducts(){
  dialogVisibleAddMaterial.value = true;
}
// 新增物料产品弹窗的确认事件
function addNewMaterialProducts(){
  newMaterialProducts.value.materialProductsTemplateId = selectByIdTestingTemplate.value.testingTemplateId;
  materialProductsRequest.loadAddMaterialProducts(newMaterialProducts.value,res=>{
    if (res.code==200){
      ElMessage({
        message: "添加成功",
        type: "success"
      })
    }
    dialogVisibleAddMaterial.value = false;
    detailTestingTemplate(selectByIdTestingTemplate.value.testingTemplateId);
  })
}
// 新增物料产品弹窗的取消事件
function cancelAddMaterialProducts(){
  dialogVisibleAddMaterial.value = false;
  newMaterialProducts.value = {};
}
// 物料产品的分页栏
function changeMaterialProducts(value){
  curPageMaterial.value = value;
  detailTestingTemplate(selectByIdTestingTemplate.value.testingTemplateId);
}
// 加载物料产品信息
function loadSelecthMaterialProducts(testingTemplateId){
  materialProductsRequest.loadMaterialProducts({materialProductsTemplateId:testingTemplateId},curPageMaterial.value,10,res=>{
    materialProductses.value = res.data.list;
    totalMaterial.value = res.data.total;
    console.log(materialProductses.value)
  })
}
// 获取被选择的检测项id
function selectTestingTemplateProject(queryTable){
  let listTestingTemplateProject = new Array();
  queryTable.forEach(item=>{
    listTestingTemplateProject.push(item.testingProjectId);
    testingTemplateProjectId.value = listTestingTemplateProject;
    console.log(listTestingTemplateProject.value)
  })
}
// 根据id进行批量删除
function deleteTestingTemplateProjects(){
  for (let i=0;i<testingTemplateProjectId.value.length;i++){
    deleteTestingTemplateProject(testingTemplateProjectId.value[i]);
  }
}
// 检测项弹窗删除按钮的点击事件
function deleteTestingTemplateProject(testingProjectId){
  testingProjectRequest.loadDeleteTestingProjectById(testingProjectId,res=>{
    if (res.code==200){
      ElMessage({
        message: "删除成功",
        type: "success"
      })
    }
  })
  detailTestingTemplate(selectByIdTestingTemplate.value)
}
// 检测项编辑弹窗的确认事件
function submitEditTestingProject(){
  testingProjectRequest.loadUpdateTestingProject(selectByIdTestingProjectTemplate.value,res=>{
    if (res.code==200){
      ElMessage({
        message: "修改成功",
        type: "success"
      })
    }
    dialogVisibleEditProject.value = false;
    detailTestingTemplate(selectByIdTestingTemplate.value)

  })
}
// 检测项编辑弹窗的取消事件
function cancelEditTestingProject(){
  dialogVisibleEditProject.value = false;
  selectByIdTestingProject.value = {};
}
// 检测项编辑按钮的点击事件
function editSubmitTestingProject(testingProjectId){
  testingProjectRequest.loadSelectByIdTestingProject(testingProjectId,res=>{
    selectByIdTestingProjectTemplate.value = res.data;
    dialogVisibleEditProject.value = true;
    console.log(selectByIdTestingProjectTemplate.value)
  })
}
// 检测项弹窗新增的确认事件
function editTestingProject(){
  testingProjectRequest.loadAddTestingProject(newTestingProject.value,res=>{
    if (res.code==200){
      ElMessage({
        message: "添加成功",
        type: "success"
      })
    }
    dialogVisibleAddProject.value = false;
    console.log(newTestingProject.value)
    newTestingProject.value = {};
  })
}
// 检测项新增按钮的点击事件
function addTestingProject(){
  dialogVisibleAddProject.value = true;
}
// 分页栏
function changePageProject(value){
  curPageProject.value = value;
  detailTestingTemplate(selectByIdTestingTemplate.value.testingTemplateId);
}
// 检测项的加载项目
function loadTestingProjectTemplateId(testingTemplateId){
  testingProjectRequest.loadTestingProject( {testingProjectTemplateId:testingTemplateId},curPageProject.value,10,res=>{
    testingTemplateProjects.value = res.data.list;
    totalProject.value = res.data.total;
    console.log(testingTemplateProjects.value)
  })
}
// 检测模版详情的点击事件
function detailTestingTemplate(testingTemplateId){
  testingTemplateRequest.loadSelectByIdTestingTemplate(testingTemplateId,res=>{
    dialogVisibleDetail.value = true;
    selectByIdTestingTemplate.value = res.data;
  })
  loadTestingProjectTemplateId(testingTemplateId);
  loadSelecthMaterialProducts(testingTemplateId);

}
// 获取被选中的检测模板id
function selectTestingTempalate(queryTable){
  let listTestingTemplate = new Array();
  queryTable.forEach(item=>{
    listTestingTemplate.push(item.testingTemplateId);
    selectTestingTemplateId.value = listTestingTemplate;
    console.log(selectTestingTemplateId.value)
  })
}
// 批量删除的点击事件
function deleteTestingTemplates(){
  for (let i = 0; i < selectTestingTemplateId.value.length; i++){
    deleteTestingTemplateById(selectTestingTemplateId.value[i]);
  }
}
// 删除按钮的点击事件
function deleteTestingTemplateById(testingTemplateId){
  testingTemplateRequest.loadDeleteTestingTemplateById(testingTemplateId,res=>{
    if (res.code == 200){
      ElMessage({
        message: "删除成功",
        type: "success"
      })
    }
    loadTestingTemplate();
  })
}
// 编辑弹窗的确定按钮
function submitEditTestingTemplate(){
  testingTemplateRequest.loadUpdateTestingTemplate(selectByIdTestingTemplate.value,res=>{
    if (res.code == 200){
      ElMessage({
        message: "修改成功",
        type: "success"
      })
    }
    dialogVisibleEdit.value = false;
    loadTestingTemplate();
  })
}
// 编辑弹窗的取消事件
function cancelEditTestingTemplate(){
  dialogVisibleEdit.value = false;
  selectByIdTestingTemplate.value = {};
}
// 编辑按钮的点击事件
function editTestingTemplate(testingTemplateId){
  testingTemplateRequest.loadSelectByIdTestingTemplate(testingTemplateId,res=>{
    selectByIdTestingTemplate.value = res.data;
    dialogVisibleEdit.value = true;
    console.log(selectByIdTestingTemplate.value)
  })
}
// 新增弹窗的确定事件
function submitAddTetstingProject(){
  testingTemplateRequest.loadAddTestingTemplate(newTestingTemplate.value,res=>{
    if (res.code == 200){
      ElMessage({
        message: "添加成功",
        type: "success"
      })
    }
    addDialogVisible.value = false;
    console.log(newTestingTemplate.value)
    newTestingTemplate.value = {};
    loadTestingTemplate();
  })
}
// 新增弹窗的取消事件
function cancelAddTestingProject(){
  addDialogVisible.value = false;
  newTestingTemplate.value = {};
}
// 新增按钮的点击事件
function addTestingTemplate(){
  addDialogVisible.value = true;
}
// 加载项目列表
function loadTestingTemplate(){
  testingTemplateRequest.loadSelectAllTestingTemplate(testingTemplateQuery.value,curPage.value,10,res=>{
    total.value = res.data.total;
    testingTemplates.value = res.data.list;
    console.log(testingTemplates.value)
  })
}
// 分页事件
function changePage(value){
  curPage.value = value;
  loadTestingTemplate();

}
onMounted(()=>{
  loadTestingTemplate();
})
</script>
<style scoped>

</style>